package com.kania.todostack;

import java.util.ArrayList;

import android.content.Context;
import android.drm.DrmStore.RightsStatus;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class TodoViewGroup extends ViewGroup{
	ArrayList<DateView> listDate = new ArrayList<DateView>();
	ArrayList<Integer> listLineHeight = new ArrayList<Integer>();
	int nDatePaintStart = 0;
	int nDateGap = 0;
	int nDateLeftStart = 0;
	int nDateRightEnd = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150.0f, getResources().getDisplayMetrics());
	int nDateTopEnd = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20.0f, getResources().getDisplayMetrics());;
	int nAddSubBtnTop = 50;
	int nAddSubBtnBottom = 100;
	int nAddSubBtnWidth = 50;
	int nFontSize = 10;

	public TodoViewGroup(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
	}
	public TodoViewGroup(Context context, AttributeSet set) {
		super(context, set);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		int childCount = getChildCount();
		/*
		l = 0;
		t = 0;
		r = 90;
		b = 20;
		*/
		listLineHeight.clear();
		for(int i = 0; i < childCount; i++){
			View v = getChildAt(i);
			if(v instanceof TodoView){
				TodoView tv = (TodoView)v;
				tv.layout(tv.left, tv.top, tv.right, tv.bottom);
			}
			else if(v instanceof SubjectView){
				SubjectView sv = (SubjectView)v;
				sv.layout(sv.left, sv.top, sv.right, sv.bottom);
				nAddSubBtnTop = sv.top;
				nAddSubBtnBottom = sv.bottom;
			}
			else if(v instanceof DateView){
				DateView dv = (DateView)v;
				dv.layout(dv.left, dv.top, dv.right, dv.bottom);
				dv.setGravity(Gravity.CENTER);
				listLineHeight.add(dv.top - 4);
			}
			else if(v instanceof TextView){
				TextView btn = (TextView)v;
				btn.layout(nDateRightEnd, nAddSubBtnTop, nDateRightEnd + (nAddSubBtnBottom - nAddSubBtnTop), nAddSubBtnBottom);
				//btn.layout(10, 10, 100, 100);
			}
		}
	}
	
	@Override
	protected void onDraw(Canvas canvas){
		Paint paint = new Paint();
		paint.setColor(Color.BLACK);
		paint.setStyle(Style.STROKE);
		paint.setPathEffect(new DashPathEffect(new float[]{2, 5}, 2));
		paint.setStrokeWidth(1);
		
		//ù��°�� delayed �̹Ƿ� ����ǥ�� ���� ���� and �������� �Ǽ�ó���ϱ� ���� ó������ �ʴ´�
		for(int i = 1; i < listLineHeight.size() - 1; i++){
			canvas.drawLine(nDateLeftStart, listLineHeight.get(i), nDateRightEnd, listLineHeight.get(i), paint);
		}
		
//		for(Integer i : listLineHeight){
//			canvas.drawLine(nDateLeftStart, (int)i, nDateRightEnd, (int)i, paint);
//		}
//		
		paint.setPathEffect(null);
		paint.setStrokeWidth(2);
		canvas.drawLine(nDateLeftStart, listLineHeight.get(listLineHeight.size()-1), nDateRightEnd, listLineHeight.get(listLineHeight.size()-1), paint);
		
//		paint.setTextAlign(Align.LEFT);
//		paint.setTextSize(nFontSize);
//		paint.setColor(Color.BLACK);
//		
//		for(int i = 0; i < listDate.size(); i++){
//			canvas.drawText(listDate.get(i), nLeftStart, nDatePaintStart-(i*nDateGap), paint);
//		}
		
	}
	public void initDateList(){
		listDate.clear();
	}
	public void addDateList(DateView dv){
		listDate.add(dv);
	}
}